DEFINITION MODULE DeviceMgr;  (* 20 Mar 87 by Tim Myers *)

(* Device Manager routines from Inside Macintosh *)

FROM SYSTEM IMPORT ADDRESS;
FROM FileMgr IMPORT
	OSType, OSErr, Ptr, ProcPtr, LONGINT, Str255, StringPtr, SignedByte,
	FInfo, QElemPtr;


EXPORT QUALIFIED
    OpenDriver, CloseDriver, FSRead, FSWrite, Control, Status, KillIO,
    ParamBlkType, ParamBlockRec, ParmBlkPtr, DCtlHandle, DCtlPtr, DCtlEntry,
    fsCurPerm, fsRdPerm, fsWrPerm, fsRdWrPerm,
    fsAtMark, fsFromStart, fsFromMark, rdVerify,
    PBOpen, PBClose, PBRead, PBWrite, PBControl, PBStatus, PBKillIO;

TYPE Handle    = POINTER TO Ptr;
	WindowPtr  = ADDRESS;
	QHdrPtr    = POINTER TO QHdr;
	QHdr = RECORD
		qFlags: INTEGER;
		qHead:	QElemPtr;
		qTail:	QElemPtr
	END;
	csParamType = ARRAY[0..10] OF INTEGER;	(* These types are needed *)
	csPtr = POINTER TO csParamType;  (* due to Modula's strong type checking *)

CONST
    fsCurPerm   = 0;
    fsRdPerm    = 1;
    fsWrPerm    = 2;
    fsRdWrPerm  = 3;
    
    fsAtMark    = 0;
    fsFromStart = 1;
    fsFromMark  = 3;
    rdVerify    = 64;

TYPE
    ParamBlkType = (ioParam, fileParam, volumeParam, cntrlParam);
    ParmBlkPtr = POINTER TO ParamBlockRec;
	ParamBlockRec = RECORD
	  qLink:		QElemPtr;		(* next queue entry *)
	  qType:		INTEGER;		(* queue type *)
	  ioTrap:		INTEGER;		(* routine trap *)
	  ioCmdAddr:	Ptr;			(* routine address *)
	  ioCompletion: ProcPtr;		(* completion routine *)
	  ioResult:		OSErr;			(* result code *)
	  ioNamePtr:	StringPtr;		(* pathname *)
	  ioVRefNum:	INTEGER;		(* volume reference or drive number *)

	CASE ParamBlkType OF
	  ioParam:
	    ioRefNum:		INTEGER;	(* path reference number *)
	    ioVersNum:		SignedByte;	(* version number *)
	    ioPermssn:		SignedByte;	(* read/write permission *)
	    ioMisc:			Ptr;		(* miscellaneous *)
	    ioBuffer:		Ptr;		(* data buffer *)
	    ioReqCount:		LONGINT;	(* requested number of bytes *)
	    ioActCount:		LONGINT;	(* actual number of bytes *)
	    ioPosMode:		INTEGER;	(* positioning mode and newline character *)
	    ioPosOffset:	LONGINT;	(* positioning offset *)
     | fileParam:
	    ioFRefNum:		INTEGER;	(* path reference number *)
	    ioFVersNum:		SignedByte;	(* version number *)
	    filler1:		SignedByte;	(* not used *)
	    ioFDirIndex:	INTEGER;	(* directory index *)
	    ioFlAttrib:		SignedByte;	(* file attributes *)
	    ioFlVersNum:	SignedByte;	(* version number *)
	    ioFlFndrInfo:	FInfo;		(* information used by the finder *)
	    ioFlNum:		LONGINT;	(* file number *)
	    ioFlStBlk:		INTEGER;	(* first allocation block of data fork *)
	    ioFlLgLen:		LONGINT;	(* logical end-of-file of data fork *)
	    ioFlPyLen:		LONGINT;	(* physical end-of-file of data fork *)
	    ioFlRStBlk:		INTEGER;	(* first allocation block of resource fork *)
	    ioFlRLgLen:		LONGINT;	(* logical end-of-file of resource fork *)
	    ioFlRPyLen:		LONGINT;	(* physical end-of-file of resource fork *)
	    ioFlCrDat:		LONGINT;	(* date and time of creation *)
	    ioFlMdDat:		LONGINT;	(* date and time of last modification *)
	| volumeParam:
	    filler2:		LONGINT;	(* not used *)
	    ioVolIndex:		INTEGER;	(* volume index *)
	    ioVCrDate:		LONGINT;	(* date and time of initialization *)
	    ioVLsBkUp:		LONGINT;	(* date and time of last modification *)
	    ioVAtrb:		INTEGER;	(* volume attributes *)
	    ioVNmFls:		INTEGER;	(* number of files in directory *)
	    ioVDirSt:		INTEGER;	(* first block of directory *)
	    ioVBlLn:		INTEGER;	(* length of directory in blocks *)
	    ioVNmAlBlks:	INTEGER;	(* number of allocation blocks *)
	    ioVAlBlkSiz:	LONGINT;	(* size of allocation blocks *)
	    ioVClpSiz:		LONGINT;	(* number of bytes to allocate *)
	    ioAlBlSt:		INTEGER;	(* first block in block map *)
	    ioVNxtFNum:		LONGINT;	(* next unused file number *)
	    ioVFrBlk:		INTEGER;	(* number of unused allocation blocks *)
	| cntrlParam:
	    ioCRefNum:		INTEGER;	(* driver reference number *)
		csCode:			INTEGER;	(* type of control of status information *)
		csParam:		csParamType; (* control or status information *)
	END (* CASE *)
	END; (* ParamBlockRec *)
	
	DCtlHandle = POINTER TO DCtlPtr;
	DCtlPtr    = POINTER TO DCtlEntry;
	DCtlEntry  = RECORD
		dCtlDriver:		Ptr;
		dCtlFlags:		INTEGER;
		dCtlQHdr:		QHdr;
		dCtlPosition:	LONGINT;
		dCtlStorage:	Handle;
		dCtlRefNum:		INTEGER;
		dCtlCurTicks:	LONGINT;
		dCtlWindow:		WindowPtr;
		dCtlDelay:		INTEGER;
		dCtlEMask:		INTEGER;
		dCtlMenu:		INTEGER;
	END;

PROCEDURE OpenDriver  (name: StringPtr; VAR refNum: INTEGER): OSErr;
PROCEDURE CloseDriver (refNum: INTEGER): OSErr;

PROCEDURE FSRead  (refNum: INTEGER; VAR count: LONGINT; buffPtr: Ptr): OSErr;
PROCEDURE FSWrite (refNum: INTEGER; VAR count: LONGINT; buffPtr: Ptr): OSErr;
PROCEDURE Control (refNum: INTEGER; csCode: INTEGER; csParamPtr: csPtr): OSErr;
PROCEDURE Status  (refNum: INTEGER; csCode: INTEGER; csParamPtr: csPtr): OSErr;
PROCEDURE KillIO  (refNum: INTEGER): OSErr;

PROCEDURE PBOpen    (paramBlock: ParmBlkPtr; async: BOOLEAN): OSErr;
PROCEDURE PBClose   (paramBlock: ParmBlkPtr; async: BOOLEAN): OSErr;
PROCEDURE PBRead    (paramBlock: ParmBlkPtr; async: BOOLEAN): OSErr;
PROCEDURE PBWrite   (paramBlock: ParmBlkPtr; async: BOOLEAN): OSErr;
PROCEDURE PBControl (paramBlock: ParmBlkPtr; async: BOOLEAN): OSErr;
PROCEDURE PBStatus  (paramBlock: ParmBlkPtr; async: BOOLEAN): OSErr;
PROCEDURE PBKillIO  (paramBlock: ParmBlkPtr; async: BOOLEAN): OSErr;

END DeviceMgr.
